﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/29/2009
 * Time: 12:57 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of EmployeeForm.
	/// </summary>
	public partial class EmployeeForm : BaseForm
	{
		public EmployeeForm() : this(new Employee())
		{
			
		}
		
		public EmployeeForm(Employee e)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Model = e;
			comboBoxChangeTabs.SelectedIndex = 0;
		}
		
		protected override void OnModelChanged(EventArgs ev)
		{
			base.OnModelChanged(ev);
			Employee e = Model as Employee;
			textBoxTitle.Text = e.Name.Title;
			textBoxLastName.Text = e.Name.Last;
			textBoxFirstName.Text = e.Name.First;
			textBoxMI.Text = e.Name.Middle;
			textBoxPrintOnCheckAs.Text = e.PrintOnCheckAs;
			textBoxSSNo.Text = e.SSNo;
			comboBoxGender.SelectedIndex = e.Gender;
			dateTimePickerDateOfBirth.Value = e.DateOfBirth;
			textBoxStreet1.Text = e.Address.Street1;
			textBoxStreet2.Text = e.Address.Street2;
			textBoxCity.Text = e.Address.City;
			comboBoxState.SelectedIndex = e.State;
			textBoxZip.Text = e.Address.Zip;
			textBoxPhone.Text = e.Phone;
			textBoxCellular.Text = e.Cellular;
			textBoxAltPhone.Text = e.AltPhone;
			textBoxFax.Text = e.Fax;
			textBoxEmail.Text = e.Email;
			textBoxPager.Text = e.Pager;
			textBoxPINPager.Text = e.PINPager;
			textBoxAccountNo.Text = e.AccountNo;
			textBoxIdNo.Text = e.IDNo;
		}
		
		void ButtonOkClick(object sender, EventArgs ev)
		{
			Employee e = Model as Employee;
			e.Name = new Name(textBoxTitle.Text, textBoxLastName.Text, textBoxFirstName.Text, textBoxMI.Text);
			e.PrintOnCheckAs = textBoxPrintOnCheckAs.Text;
			e.SSNo = textBoxSSNo.Text;
			e.Gender = comboBoxGender.SelectedIndex;
			e.DateOfBirth = dateTimePickerDateOfBirth.Value;
			e.Address = new Address(textBoxStreet1.Text, textBoxStreet2.Text, textBoxCity.Text, "", textBoxZip.Text, "", "");
			e.State = comboBoxState.SelectedIndex;
			e.Phone = textBoxPhone.Text;
			e.Cellular = textBoxCellular.Text;
			e.AltPhone = textBoxAltPhone.Text;
			e.Fax = textBoxFax.Text;
			e.Email = textBoxEmail.Text;
			e.Pager = textBoxPager.Text;
			e.PINPager = textBoxPINPager.Text;
			e.AccountNo = textBoxAccountNo.Text;
			e.IDNo = textBoxIdNo.Text;
			SessionFacade.SaveOrUpdateEmployee(e);
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
		
		void TextBoxNameTextChanged(object sender, EventArgs e)
		{
			labelName.Text = new Name(textBoxLastName.Text, textBoxFirstName.Text, textBoxMI.Text).ToString();
		}
		
		void ComboBoxChangeTabsSelectedIndexChanged(object sender, EventArgs e)
		{
			switch (comboBoxChangeTabs.SelectedIndex) {
				case 0:
					tabControl1.TabPages.Clear();
					tabControl1.TabPages.AddRange(new TabPage[] { tabPage1, tabPage2, tabPage3 });
					break;
				case 1:
					tabControl1.TabPages.Clear();
					tabControl1.TabPages.AddRange(new TabPage[] { tabPage4 });
					break;
				case 2:
					tabControl1.TabPages.Clear();
					tabControl1.TabPages.AddRange(new TabPage[] { tabPage5 });
					break;
				case 3:
					tabControl1.TabPages.Clear();
					tabControl1.TabPages.AddRange(new TabPage[] { tabPage6 });
					break;
				case 4:
					tabControl1.TabPages.Clear();
					tabControl1.TabPages.AddRange(new TabPage[] { tabPage7 });
					break;
				default:
					break;
			}
		}
		
		void ButtonDefineFieldsClick(object sender, EventArgs e)
		{
			
		}
	}
}
